package edu.zut.test;

import edu.zut.main.pojo.SysUser;
import edu.zut.main.util.DBUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class JDBCQuery {


    public static void main(String[] args) throws SQLException {
        //查询全部 sys_user
        String sql = "select user_id id,user_code code,user_name name,user_password psw,user_state state from sys_user";
        ResultSet rs = DBUtil.query(sql, null);
        List<SysUser> list = new ArrayList<>();
        while (rs.next()){
            //从结果集中依次获取数据
            int user_id = rs.getInt("id");
            String user_code = rs.getString("code");
            String user_name = rs.getString("name");
            String user_password = rs.getString("psw");
            int user_state = rs.getInt("state");
            //将数据再次封装成一个对象
            SysUser sysUser = new SysUser(user_id, user_code, user_name, user_password, user_state);
            list.add(sysUser);
        }
        System.out.println("list = " + list);
        DBUtil.free();
    }

}
